package com.example.smartcity4.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity4.MainActivity;
import com.example.smartcity4.R;
import com.example.smartcity4.javaBean.GsonBean;

import java.util.List;

public class ServiceAdapter extends BaseAdapter {
    private List<GsonBean.Rows>rows;

    public ServiceAdapter(List<GsonBean.Rows> rows, Context context) {
        this.rows = rows;
        this.context = context;
    }

    private Context context;
    @Override
    public int getCount() {
        return rows.size();
    }

    @Override
    public Object getItem(int position) {
        return rows.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView= LayoutInflater.from(context).inflate(R.layout.service_itme,parent,false);
        ImageView imageView=convertView.findViewById(R.id.service_image);
        TextView textView=convertView.findViewById(R.id.service_text);
        textView.setText(rows.get(position).serviceName);
        Glide.with(context).load(MainActivity.host+rows.get(position).imgUrl).into(imageView);
        return convertView;
    }
}
